﻿Ext.define('Kwan.ex.Grid', {
    extend: 'Ext.grid.Panel',
    border: false, forceFit: true, layout: 'fit', columnLines: true, loadMask: true, frame: true,
    viewConfig: { stripeRows: true },
    //al: true, // 自动加载
    selType: 'checkboxmodel', //设定选择模式
    //selModel: Ext.create('Ext.selection.CheckboxModel'),
    multiSelect: true,  //运行多选
    noPagging: false,   //分页
    operBar: {},        //操作栏
    modelFields: [],    //store Fields
    dataUrl: '',        //store url
    columns: [],
    defSort: [{ property: 'EntityID', direction: 'DESC'}],
    isSample: false,
    initComponent: function () {
        var me = this;
        this.buildFilters = function () {
            var filtersArray = [];
            Ext.each(this.columns, function (c) {
                if (c.noFilter != true) {
                    filtersArray[filtersArray.length] = {
                        dataIndex: c.dataIndex,
                        type: c.type
                    };
                }
            });
            //Kwan.Debug(filtersArray[2]);
            return filtersArray;
        };
        Ext.apply(this.features, {
            ftype: 'filters',
            encode: true,
            menuFilterText: '检索',
            updateBuffer: 1000,
            filters: this.buildFilters()
        });
        var bbarItems = this.isSample ? [] :
        [{
            icon: '/Admin/style/16Icons/lightning.png',
            tooltip: '重置查询',
            scope: this,
            handler: function () {
                this.getQuery(true);
            }
        },
        { xtype: "label", text: "每页显示:" },
        { xtype: "tbspacer", width: 10 },
        { xtype: "combo", width: 80, value: "20", editable: false, displayField: "text", valueField: "value", submitValue: true, emptyMsg: "没有可显示的数据",
            store: new Ext.data.SimpleStore({ fields: ["text", "value"], data: [["10", "10"], ["20", "20"], ["50", "50"], ["100", "100"]] }),
            listeners: {
                select: { fn: function (item, record, index) { me.store.pageSize = parseInt(this.getValue()); me.store.load(); } }
            }
        }];
        this.bbar = Ext.create('Ext.PagingToolbar', {
            store: this.store,
            pageSize: 20,
            displayInfo: true,
            plugins: Ext.create('Ext.ux.ProgressBarPager', {}),
            items: bbarItems
        });

        this.tbar = this.operBar;
        this.callParent(arguments);
    }

});